package com.zbkj.crmebadmin.service.impl;

import com.zbkj.common.model.system.SystemMenu;
import com.zbkj.common.response.MenusResponse;
import com.zbkj.common.vo.MenuTree;
import com.zbkj.crmebadmin.service.AdminLoginService;
import com.zbkj.service.service.SystemMenuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AdminLoginServiceImpl implements AdminLoginService {
    @Autowired
    private SystemMenuService systemMenuService;

    @Override
    public List<MenusResponse> getMenus() {
        List<SystemMenu> menuList;
//        menuList = systemMenuService.findAllCatalogue();
        Integer num1 = 1;
        menuList = systemMenuService.getMenusByUserId(num1);
        // 组装前端对象
        List<MenusResponse> responseList = menuList.stream().map(e -> {
            MenusResponse response = new MenusResponse();
            BeanUtils.copyProperties(e, response);
            return response;
        }).collect(Collectors.toList());
        MenuTree menuTree = new MenuTree(responseList);
        return menuTree.buildTree();
    }
}
